#ifndef TYPE_H
#define TYPE_H

#include <stdint.h>
#include <stdbool.h>

// 结构体定义
typedef struct __attribute__ ((__packed__)) {
    uint8_t frame_header;
    uint8_t id;
    uint8_t length;
    uint8_t cmd;
    uint8_t null;
    uint8_t data[6];
    uint8_t crc16L;
    uint8_t crc16H;
} Motor_Ctr;

typedef struct __attribute__ ((__packed__)) {
    float dist;
} Stepmotor_Ctr;

typedef struct __attribute__ ((__packed__)) {
    float servo_head_x;  // 单位 角度0-180
    float servo_head_y;
    float servo_fin_left_out;
    float servo_fin_left_in;
    float servo_fin_right_in;
    float servo_fin_right_out;
} Servo_Ctr;

typedef struct __attribute__ ((__packed__)) {
    uint8_t headL;
    uint8_t headH;
    uint8_t len;
    uint8_t cmd;
    Motor_Ctr motor_ctr;
    Stepmotor_Ctr stepmotor_ctr;
    Servo_Ctr servo_ctr;
    uint8_t crc16L;
    uint8_t crc16H;
} Host_Ctr_Cmd;

// 全局变量声明
extern Host_Ctr_Cmd host_ctr_cmd_g;
extern int motor_speed;
extern bool trans_flag;
extern bool con_flag ;

extern int motor_add_flag;
extern int stepmotor_add_flag;
extern int headx_add_flag;
extern int heady_add_flag;
extern int fin_left_out_add_flag;
extern int fin_left_in_add_flag;
extern int fin_right_in_add_flag;
extern int fin_right_out_add_flag;

// 宏定义
#define SPEED_CLOSEDLOOP_CTR            0xA2

#define JOYSTICK_CMD                    0x02U
#define SHELL_OPEN                      0x08U
#define POWER_ON                        0x011U
#define POWER_OFF                       0x012U

#define MOTOR_SPEED_MAX                 1500
#define STEPMOTOR_MAXDIST               14
#define SERVO_HEAD_MAX                  135
#define SERVO_HEAD_MIN                  45
#define SERVO_FIN_MAX                   180
#define SERVO_FIN_MIN                   0

#define Servo_Fin_Left_In_init          179
#define Servo_Fin_Right_In_init         0

#define SHMSIZE                         10

#endif // TYPES_H